package assignment10;

import java.io.*;

class CopyFile {
	public static void main (String[] args) {
		if (args.length < 2) {
			//命令行参数个数小于2直接退出
			System.out.println("Please enter file names");
			return;
			}
		//创建字节处理流对象
		DataInputStream instr;
		DataOutputStream outstr;
		try {
			//创建文件读写流对象, 使用缓冲器处理
			instr = new DataInputStream(new BufferedInputStream(new FileInputStream(args[0])));
			outstr = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(args[1])));
			try {
				int data;
				//死循环, 出现异常则跳出循环
				while (true) {
					data = instr.readUnsignedByte();
					outstr.writeByte(data);
				}
			}
			//捕获到异常说明读完了, 此时需要关闭流
			catch (EOFException  eof) {
				outstr.close();
				instr.close();
				return;
			}
		}
		//其他异常处理
		catch (FileNotFoundException nfx) {
			System.out.println("FileNotFuond");
		}
		catch (IOException iox) {
			System.out.println("IO Problems");
		}
	}
}